package com.example.flow.hook;

import com.neuronbit.businessflow.runtime.Flow;
import com.neuronbit.businessflow.runtime.FlowContext;
import com.neuronbit.businessflow.runtime.Step;
import com.neuronbit.businessflow.runtime.lifecycle.StepLifecycleHook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class StepHook implements StepLifecycleHook {
    @Override
    public boolean support(FlowContext context, Flow flow, Step<?> step) {
        return true;
    }

    @Override
    public void onEnd(FlowContext flowContext, Flow flow, Step step) {
        log.info("{}/{} end", step.getName(), flow.getName());
    }

    @Override
    public void onError(FlowContext flowContext, Flow flow, Step step, Exception e) {
        log.info("{}/{} error", step.getName(), flow.getName(), e);
    }

    @Override
    public void onStart(FlowContext flowContext, Flow flow, Step step) {
        log.info("{}/{} start", step.getName(), flow.getName());
    }

    @Override
    public void onSkipped(FlowContext flowContext, Flow flow, Step step) {
        log.info("{}/{} onSkipped", step.getName(), flow.getName());
    }

    @Override
    public void onPause(FlowContext flowContext, Flow flow, Step step) {
        log.info("{}/{} onPause", step.getName(), flow.getName());
    }

}
